import { makeAutoObservable } from 'mobx'
import { Authorization } from '../requests'
import { LoginDto } from '../dtos'

export default new (class Auth {
    isLogIn: boolean = false
    constructor() {
        makeAutoObservable(this)
    }
    LogIn(userData: LoginDto) {
        Authorization(userData).then((data) => {
            if (data.statusCode == undefined) {
                localStorage.token = data.access_token
                this.isLogIn = true
            } else if (data.statusCode > 400) alert('неверное имя пользователя или пароль')
        })
    }
    LogOut() {
        localStorage.removeItem('token')
        this.isLogIn = false
    }
})()
